/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jrill;

import java.util.Date;
import java.util.List;
import org.jrill.notification.MessageTemplate;
import org.jrill.notification.Notifier;

/**
 * Representative of a task, or sets of activities that shoud be processed in a standardized style.
 * @author K.Waga
 */
public interface Workflow {
    /**
     * default activities length
     */
    int DEFAULT_ACTIVITIES_LENGTH = 10;
    /**
     * Indicates workflow is in draft
     */
    long STATUS_DRAFT = 0L;
    /**
     * Indicates workflow has finished
     */
    long STATUS_FINISHED = -1L;
    /**
     * Indicates workflow is on-going status
     */
    long STATUS_ON_GOING = 1L;

    /**
     * Returns index of specified activity, or -1 if this workfrow contains no such activity.
     * @param activity activity to search for
     * @return
     */
    int activityIndexOf(Activity activity);

    /**
     * Adds specified activity to the workflow.
     * @param activity activity to add
     */
    void addActivity(Activity activity);

    /**
     * Declines workflow by specified owner. This roll backs activities to previous owner.
     * @param owner participant who declines this workflow
     */
    void decline(Participant owner);

    /**
     * Declines workflow by specified owner with specified message. This roll backs activities to previous owner.
     * @param owner participant who declines this workflow
     * @param message message to leave
     */
    void decline(Participant owner, String message);

    /**
     * Declines workflow by specified owner with specified message, and notify particioants using specified message template. This roll backs activities to previous owner.
     * @param owner  participant who declines this workflow
     * @param message message to leave
     * @param messageTemplate template of notification message
     */
    void decline(Participant owner, String message, MessageTemplate messageTemplate);

    /**
     * Find the list of current activities
     * @return current activities
     */
    List<Activity> findCurrentActivity();

    /**
     * Returns activity at specified index.
     * @param index zero-originned activity index to get
     * @return activity with specified index
     */
    Activity getActivity(int index);

    /**
     * Returns the date workflow has finished.
     * @return the date workflow finished
     */
    Date getFinished();

    /**
     * Returns workflow id.
     * @return workflow id
     */
    Long getId();

    /**
     * Returns workflow name.
     * @return the name
     */
    String getName();
    
    /**
     * Returns {@link Notifier}. 
     */
    Notifier getNotifier();

    /**
     * Returns the date workflow has started.
     * @return the started
     */
    Date getStarted();

    /**
     * Returns the current workflow status.
     * @return the status
     */
    Long getStatus();

    /**
     * Returns the workflow type.
     * @return the type
     */
    String getType();

    /**
     * Returns the workflow version.
     * @return the version
     */
    Long getVersion();

    /**
     * Returns wether this workflow has finished.
     * @return true if the workflow has finished, otherwise false
     */
    boolean isFinished();

    /**
     * Returns if mail is enabled in this workflow.
     * @return true if mail is enabled, otherwise false
     */
    boolean isMailEnabled();

    /**
     * Proceeds this workflow by specified activity owner.
     * @param owner an activity owner
     */
    void proceed(Participant owner);

    /**
     * Proceeds workflow by specified activity owner with specified message.
     * @param owner an activity owner
     * @param message message to leave
     */
    void proceed(Participant owner, String message);

    /**
     * Proceeds workflow by specified owner with specified message, and notify particioants using specified message template.
     * @param owner an activity owner
     * @param message message to leave
     * @param messageTemplate template of notification message
     */
    void proceed(Participant owner, String message, MessageTemplate messageTemplate);

    /**
     * Rejects workflow by specified owner. This closes the workflow.
     * @param owner an activity owner
     */
    void reject(Participant owner);

    /**
     * Rejects workflow by specified owner with specified message. This closes the workflow.
     * @param owner an activity owner
     */
    void reject(Participant owner, String message);

    /**
     * Rejects workflow by specified owner with specified message, and notify particioants using specified message template. This closes the workflow.
     * @param owner an activity owner
     * @param message message to leave
     * @param messageTemplate template of notification message
     */
    void reject(Participant owner, String message, MessageTemplate messageTemplate);

    /**
     * Removes specified activity from the workflow.
     * @param activity activity to remove
     */
    void removeActivity(Activity activity);

    /**
     * Sets specified activity to specified activity index. Current acticity at there will be replaced.
     * @param i zero-origined index of activity
     * @param activity activity to set
     */
    void setActivity(int i, Activity activity);

    /**
     * Inserts specified activity to specified position of activities list. The indexes rest of activities will be incremented by 1.
     * @param i zero-origined index of activity
     * @param activity activity to insert
     */
    void insertActivity(int i, Activity activity);

    /**
     * Sets the date workflow has finished.
     * @param finished the finished date to set
     */
    void setFinished(Date finished);

    /**
     * Sets workflow id.
     * @param id id to set
     */
    void setId(Long id);

    /**
     * Sets whether mail is enabled or not
     * @param mailEnabled true if mail is enabled, otherwise false
     */
    void setMailEnabled(boolean mailEnabled);

    /**
     * Sets workflow name
     * @param name the name to set
     */
    void setName(String name);

    /**
     * Sets the date workflow has started.
     * @param started the started date to set
     */
    void setStarted(Date started);

    /**
     * Sets the workflow status (one of STATUS_DRAFT, STATUS_ON_GOING, STATUS_FINISHED)
     * @param status the status to set
     */
    void setStatus(Long status);

    /**
     * Sets the workflow type.
     * @param type the type to set
     */
    void setType(String type);

    /**
     * Sets the workflow versions
     * @param version version to set
     */
    void setVersion(Long version);

    /**
     * Sets SendTo: notification destinations on workflow completion.
     * @param sendTo destinations to set
     */
    void setSendTo(List<Recipient> sendTo);
    /**
     * Returns SendTo notification destinations on workflow completion.
     * @return SendTo destinations
     */
    List<Recipient> getSendTo();
    /**
     * Sets CC: notification destinations on workflow completion.
     * @param copyTo cc: destinations to set
     */
    void setCopyTo(List<Recipient> copyTo);
    /**
     * Returns CC: notification destinations on workflow completion.
     * @return CC: destinations
     */
    /**
     * Returns CC: notification destinations on workflow completion.
     * @return CC: destinations
     */
    List<Recipient> getCopyTo();
    /**
     * Sets BCC: notification destinations on workflow completion.
     * @param bcc bcc: destinations to set
     */
    void setBlindCopyTo(List<Recipient> bcc);
    /**
     * Returns BCC: notification destinations on workflow completion.
     * @return BCC: destinations
     */
    List<Recipient> getBlindCopyTo();
    /**
     * Returns number of activities
     * @return number os activities
     */
    int size();

    /**
     * Removes all blank activities.
     */
    void trim();
}
